package com.gitee.feizns.quickstart.ding.talk.api.v10.yida.forms;

import com.aliyun.dingtalkyida_1_0.Client;
import com.aliyun.dingtalkyida_1_0.models.GetFieldDefByUuidHeaders;
import com.aliyun.dingtalkyida_1_0.models.GetFieldDefByUuidRequest;
import com.aliyun.dingtalkyida_1_0.models.GetFieldDefByUuidResponse;
import com.aliyun.dingtalkyida_1_0.models.GetFieldDefByUuidResponseBody;
import com.aliyun.teautil.models.RuntimeOptions;
import com.gitee.feizns.quickstart.ding.talk.client.Clients;
import com.gitee.feizns.quickstart.ding.talk.utils.Utils;
import lombok.SneakyThrows;

import java.util.List;

/**
 * 获取表单内的组件信息（/v1.0/yida/forms/formFields）
 * 接口路径：<a href="https://open.dingtalk.com/document/orgapp/get-form-field-information-based-on-form-uuid">获取表单内的组件信息（/v1.0/yida/forms/formFields）</a>
 * @link <a href="https://open.dingtalk.com/document/orgapp/get-form-field-information-based-on-form-uuid">服务端API 宜搭应用开发 表单 获取表单内的组件信息</a>
 * @author feizns
 * @since 2024/4/1
 */
public class FormFields {

    /**
     * 获取表单内的组件信息
     * @param accessToken 访问凭据
     * @param req 请求
     * @return {@link List}<{@link GetFieldDefByUuidResponseBody.GetFieldDefByUuidResponseBodyResult}>
     */
    @SneakyThrows
    public static List<GetFieldDefByUuidResponseBody.GetFieldDefByUuidResponseBodyResult> execute(String accessToken, GetFieldDefByUuidRequest req) {
        //客户端
        Client client = Clients.get(Client.class);
        //请求头
        GetFieldDefByUuidHeaders headers = headers(accessToken);
        //响应
        GetFieldDefByUuidResponse resp = client.getFieldDefByUuidWithOptions(req, headers, new RuntimeOptions());
        GetFieldDefByUuidResponseBody body = Utils.ifErrorThrow(resp.getBody());
        return body.getResult();
    }

    /**
     * 请求头
     * @param accessToken 访问凭据
     * @return {@link GetFieldDefByUuidHeaders}
     */
    public static GetFieldDefByUuidHeaders headers(String accessToken) {
        com.aliyun.dingtalkyida_1_0.models.GetFieldDefByUuidHeaders headers = new com.aliyun.dingtalkyida_1_0.models.GetFieldDefByUuidHeaders();
        headers.xAcsDingtalkAccessToken = accessToken;
        return headers;
    }

}
